package com.ys.controller.api.mail;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.dto.DtreeSqlDto;
import com.ys.entity.mail.MailGroup;
import com.ys.service.mail.MailGroupService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/mailGroup")
public class ApiInterMailGroupController {
	
	@Autowired
	private CommonApiService<MailGroup> commonApiService;
	@Autowired
	private MailGroupService mailGroupService;

	@RequiresPermissions("mailGroup:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute MailGroup cond){
		
		return commonApiService.searchLay(cond);
	}


	@RequestMapping("/dtree")
    @ResponseBody
	public DtreeSqlDto dtree(Model model, HttpServletRequest request, HttpServletResponse response){
		return mailGroupService.dtree();
	}
	
	/**
	 * 新增
	 */
	@PostMapping("/add")
    @ResponseBody
	public R add(Model model, HttpServletRequest request, HttpServletResponse response,
			String name){
		
		return mailGroupService.add(name);
	}
	
	/**
	 * 编辑
	 */
	@PostMapping("/edit")
    @ResponseBody
	public R edit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id,
			String name){
		
		return mailGroupService.edit(id, name);
	}
	
	/**
	 * 获取用户列表数据（按组）
	 */
	@PostMapping("/listUser")
    @ResponseBody
	public R listUser(Model model, HttpServletRequest request, HttpServletResponse response,
			Long groupId){
		
		return mailGroupService.listUser(groupId);
	}
	
	/**
	 * 添加用户进组
	 */
	@PostMapping("/addUsers")
    @ResponseBody
	public R addUsers(Model model, HttpServletRequest request, HttpServletResponse response,
			Long groupId,
			String userArr){
		
		return mailGroupService.addUsers(groupId, userArr);
	}
}
